<?php

namespace App\Models\Reservation;

use App\Project\Traits\Model\WhereTimeBetween;
use App\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Schedule extends Model
{
    use WhereTimeBetween;

    public $timestamps = false;

    protected $table = 'st_reservation_schedules';

    protected $dates = ['deleted_at'];

    protected $fillable = [
        'doctor_id', 'time','room','workload',
    ];

    protected $casts = [
        'workload' => 'array',
    ];

    public function doctor()
    {
        return $this->belongsTo(User::class);
    }

    public function scopeWhereHospital(Builder $builder, $hospital_id)
    {
        return $builder->whereHas('doctor', function (Builder $builder) use ($hospital_id) {
            $builder->where('hospital_id', $hospital_id);
        });
    }

    public function scopeWhereDoctorAndTime(Builder $builder, $doctor_id, $time)
    {
        return $builder->where(compact('doctor_id', 'time'));
    }
}
